package com.china.mobile.ai.contorller;

import com.china.mobile.ai.dto.ChatDto;
import com.china.mobile.ai.service.ChatService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * ChatController 对话控制器
 *
 * @author: lxr
 * @Date: 2025/10/13 23:19
 * @Description:
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/chat")
public class ChatController {

    private final ChatService chatService;

    /**
     * chat 处理流式聊天请求，返回服务器发送事件（SSE）格式的响应流
     * @param: chatDto - [ChatDto]
     * @return: String
     */
    @PostMapping(value = "stream",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chat(@RequestBody ChatDto chatDto){
        return chatService.chat(chatDto.getQuestion(), chatDto.getSessionId());
    }
}
